package thread;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;

class ReaderThread_ extends Thread{
	private PipedReader pr;
	private BufferedReader br;
	
	public ReaderThread_() {
		super();
	}

	public ReaderThread_(PipedReader pr, BufferedReader br) {
		this.pr = pr;
		this.br = br;
	}
	
	public void run(){
		String buf=null;
		try {
			while ((buf=br.readLine())!=null) {
				System.out.println(buf);
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			try {
				br.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	class WriterThread extends Thread{
		String[] books=new String[]{
				"book1",
				"book2",
				"book3"
		};
		private PipedWriter pw;
		public WriterThread() {
			super();
		}
		public WriterThread(PipedWriter pw) {
			super();
				this.pw = pw;
		}
	public void run(){
		for (int i = 0; i < 100; i++) {
			try {
				this.pw.write(books[i%4]+"\n");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			finally{
				try {
					this.pw.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	}
}
class ReaderThread{
	public static void main(String[] args) {
		PipedReader pr=null;
		PipedWriter pw=null;
		try {
			pw=new PipedWriter();
			pr=new PipedReader();
			pw.connect(pr);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		
	}
}